﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

// 调用
using Catering.View_Operaction;
using System.Data;
using Microsoft.Reporting.WebForms;


namespace Catering.Catering_Page.JieGouJianKong
{
    public partial class EdibleStatisticsPage : System.Web.UI.Page
    {
        private static View_Monitor vm = new View_Monitor();
        private string AREAID, CLASSID, YEAR = "";
        // 页面 Load 事件 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["Month"]))
                {
                    BindDataForMonth();
                    if (Session["CLASSID"] != null && Session["YEAR"] != null)
                    {
                        CLASSID = Session["CLASSID"].ToString();
                        YEAR = Session["YEAR"].ToString();
                        DataTable dt = vm.GetOilResult(CLASSID, YEAR);
                        ReportDataSource rds = new ReportDataSource("DataSet1", dt);
                        ReportViewer1.LocalReport.DataSources.Clear();
                        ReportViewer1.LocalReport.DataSources.Add(rds);
                        ReportViewer1.LocalReport.Refresh();
                        ReportViewer1.Visible = true;
                    }
                }
                this.ReportViewer1.AsyncRendering = false;
                this.ReportViewer1.SizeToReportContent = false;
                this.ReportViewer1.ZoomMode = ZoomMode.Percent;
            }
        }

        private void BindDataForMonth()
        {
            if (Session["AREAID"] == null || Session["CLASSID"] == null || Session["YEAR"] == null)
            {
                return;
            }
            int companyid = 0;
            if (Session["UserID"] != null)
            {
                string userid = Session["UserID"].ToString();
                companyid = new Catering_Rules.T_Personnel().GetCompanyIDByPID(Convert.ToInt32(userid));
            }
            string Month = Request.QueryString["Month"];
            AREAID = Session["AREAID"].ToString();
            CLASSID = Session["CLASSID"].ToString();
            YEAR = Session["YEAR"].ToString();

            DataTable dt = vm.GetOilResultByMonth(companyid,AREAID, CLASSID, YEAR, Month);
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>divshow('div_bg','div_main')</script>");
            UpdatePanel1.Visible = false;
            ReportViewer2.LocalReport.ReportPath = @"Catering_Page\Jiegoujiankong\Report\EdibleStatistics_Month_rp.rdlc";
            ReportViewer2.LocalReport.DataSources.Clear();
            ReportViewer2.LocalReport.DataSources.Add(rds);
            ReportViewer2.LocalReport.Refresh();

            ReportViewer2.AsyncRendering = false;
            ReportViewer2.SizeToReportContent = false;
            ReportViewer2.ZoomMode = ZoomMode.Percent;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            CLASSID = DDLTool2.GetDDL_Class();
            YEAR = DDLTool2.GetYear();
            if (string.IsNullOrEmpty(YEAR))
            {
                return;
            }
            Session["AREAID"] = DDLTool2.GetDDL_Area();
            Session["CLASSID"] = CLASSID;
            Session["YEAR"] = YEAR;
            DataTable dt = vm.GetOilResult(CLASSID, YEAR);
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();
            ReportViewer1.Visible = true;
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            YEAR = DDLTool2.GetYear();
            CLASSID = DDLTool2.GetDDL_Class();
            if (string.IsNullOrEmpty(YEAR))
            {
                return;
            }
            ReportViewer2.LocalReport.ReportPath = @"Catering_Page\Jiegoujiankong\Report\EdibleStatistics_Year_rp.rdlc";
            DataTable dt = vm.GetOilOfYearResult(CLASSID, YEAR);
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ReportViewer2.LocalReport.DataSources.Clear();
            ReportViewer2.LocalReport.DataSources.Add(rds);
            ReportViewer2.LocalReport.Refresh();
            UpdatePanel1.Visible = true;
        }

        protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton1.Checked)
            {
                UpdatePanel1.Visible = true;
                YEAR = DDLTool2.GetYear();
                CLASSID = DDLTool2.GetDDL_Class();
                ReportViewer2.LocalReport.ReportPath = @"Catering_Page\Jiegoujiankong\Report\EdibleStatistics_Year_rp.rdlc";
                DataTable dt = vm.GetOilOfYearResult(CLASSID, YEAR);
                ReportDataSource rds = new ReportDataSource("DataSet1", dt);
                ReportViewer2.LocalReport.DataSources.Clear();
                ReportViewer2.LocalReport.DataSources.Add(rds);
                ReportViewer2.LocalReport.Refresh();
            }
        }

        protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButton2.Checked)
            {
                UpdatePanel1.Visible = true;
                YEAR = DDLTool2.GetYear();
                CLASSID = DDLTool2.GetDDL_Class();
                ReportViewer2.LocalReport.ReportPath = @"Catering_Page\Jiegoujiankong\Report\EdibleStatistics_List_rp.rdlc";
                DataTable dt = vm.GetOilResult(CLASSID, YEAR);
                ReportDataSource rds = new ReportDataSource("DataSet1", dt);
                ReportViewer2.LocalReport.DataSources.Clear();
                ReportViewer2.LocalReport.DataSources.Add(rds);
                ReportViewer2.LocalReport.Refresh();
            }
        }
    }
}